//216.组合总和III
//https://leetcode.cn/problems/combination-sum-iii/?envType=daily-question&envId=2024-04-21
class Solution {
    vector<int> path;
    vector<vector<int>> ret;
public:
    vector<vector<int>> combinationSum3(int k, int n) {
        dfs(k, n, 0);
        return ret;
    }

    void dfs(int k, int n, int num)
    {
        if (k == 0 && n == 0)
        {
            ret.push_back(path);
            return;
        }

        for(int i = 1; (n - (num + i) >= 0) && ((num+i) < 10);++i)
        {
            path.push_back(num + i);
            dfs(k - 1, n - (num + i), num + i);
            path.pop_back();
        }
    }
};